package com.article.controller;

import com.apis.app.ArticleAppControllerapi;
import com.article.feign.WenzhangduochaFeign;
import com.article.mapper.ApCollectionMapper;
import com.article.mapper.AparticleMappertu;
import com.article.service.AparticleServicetu;

import com.article.service.ipl.AparticleServiceimpl;
import com.usian.model.atri.ApCollection;
import com.usian.model.atri.CollectionBehaviorDto;
import com.usian.model.atri.pojos.ApArticle;
import com.usian.model.atri.pojos.dto.ArticleHomeDto;
import com.usian.model.atri.pojos.dto.ArticleInfoDto;
import com.usian.model.behavior.*;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/article/api/v1/article")
@RestController
public class ArticleAppController implements ArticleAppControllerapi {
    @Autowired
    private AparticleServicetu aparticleServicetu;

    @Resource
    WenzhangduochaFeign wenzhangduocha;

    @Resource
    com.article.mapper.AparticleMappertu AparticleMappertu;
    @Resource
    ApCollectionMapper apCollectionMapper;


    @GetMapping("list")
    public List<ApArticle> list(){
        return AparticleMappertu.selectList(null);
    }

//根据id 查询文章列表信息
    @GetMapping("wzcha")
    @Override
    public ApArticle wzcha(@RequestParam Long articleId){
        return aparticleServicetu.getById(articleId);
    }


//文章关系展示
    @PostMapping("wenzhangduocha")
    @Override
    public ResponseResult wenzhangduocha(@RequestBody ArticleInfoDto dto) {
        ApBehaviorEntry apBehaviorEntry=  wenzhangduocha.apBehaviorEntry(dto);
        ApUnlikesBehavior apUnlikesBehavior=  wenzhangduocha.apUnlikesBehavior(dto);
        ApLikesBehavior apLikesBehavior=  wenzhangduocha.apLikesBehavior(dto);
        ApFollowBehavior apFollowBehavior=  wenzhangduocha.apFollowBehavior(dto);
        ApCollection apCollection=apCollectionMapper.selectById(dto.getArticleId());
        Map<String ,Object> map=new HashMap<>();
        map.put("apBehaviorEntry",apBehaviorEntry);
        map.put("apUnlikesBehavior",apUnlikesBehavior);
        map.put("apLikesBehavior",apLikesBehavior);
        map.put("apFollowBehavior",apFollowBehavior);
        map.put("apCollection",apCollection);
        return ResponseResult.okResult(map);

    }



    @PostMapping("shoucangxingwei")
    @Override
    public ResponseResult shoucangxingwei(@RequestBody ApBehaviorEntry apBehaviorEntry,@RequestBody CollectionBehaviorDto dto) {
        return aparticleServicetu.shoucangxingwei(apBehaviorEntry,dto);
    }



    @PostMapping("load_article_info")
    @Override
    public ResponseResult wenzhangxiangqing(@RequestBody ArticleInfoDto articleInfoDto) {
        return aparticleServicetu.wenzhangxiangqing(articleInfoDto);
    }

    @PostMapping("/load")
    @Override
    public ResponseResult load(@RequestBody ArticleHomeDto dto) {
        return aparticleServicetu.load(dto,2);
    }

    @PostMapping("/loadNew")
    @Override
    public ResponseResult loadNew(@RequestBody ArticleHomeDto dto) {
        return aparticleServicetu.load(dto,2);
    }

    @PostMapping("/loadMore")
    @Override
    public ResponseResult loadMore(@RequestBody ArticleHomeDto dto) {
        return aparticleServicetu.load(dto,1);
    }
}
